home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #3 / Amiga Plus CD - 1997 - No. 03.iso / pd / programmierung / vbcc / machines / amiga68k / libsrc / amigalib / createtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-16  |  1.6 KB  |  65 lines

  1. /*
  2. ** compiles with inline only in large data! AddTask() uses too many
  3. ** nonscratch registers :( use of assembler version is recommended
  4. */
  5. #include <exec/tasks.h>
  6. #include <exec/memory.h>
  7. #include <exec/execbase.h>
  8. #include <clib/alib_protos.h>
  9. #include <clib/exec_protos.h>
  10.  
  11. struct newMemList
  12. {
  13.   struct Node nml_Node;
  14.   UWORD nme_NumEntries;
  15.   struct MemEntry nml_ME[2];
  16. };
  17.  
  18. const struct newMemList MemTemplate =
  19. { {0,},
  20.   2,
  21.   { {MEMF_CLEAR|MEMF_PUBLIC, sizeof(struct Task)},
  22.     {MEMF_CLEAR, 0} }
  23. };
  24.  
  25. struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize)
  26. {
  27.   struct Task *newtask,*task2;
  28.   struct newMemList nml;
  29.   struct MemList *ml;
  30.  
  31.   stacksize=(stacksize+3)&~3;
  32.   {
  33.     long *p1,*p2;
  34.     int i;
  35.  
  36.     for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ;
  37.     *p1=stacksize;
  38.   }
  39. /*  if (!(((unsigned int)ml=AllocEntry((struct MemList *)&nml)) & (1<<31)))*/
  40. /*  was dieser gcc alles als lvalue durchgehen laesst...    */
  41.   ml=AllocEntry((struct MemList *)&nml);
  42.   if(!((unsigned int)ml&(1<<31)))
  43.   {
  44.     newtask=ml->ml_ME[0].me_Addr;
  45.     newtask->tc_Node.ln_Type=NT_TASK;
  46.     newtask->tc_Node.ln_Pri=pri;
  47.     newtask->tc_Node.ln_Name=name;
  48.     newtask->tc_SPReg=(APTR)((ULONG)ml->ml_ME[1].me_Addr+stacksize);
  49.     newtask->tc_SPLower=ml->ml_ME[1].me_Addr;
  50.     newtask->tc_SPUpper=newtask->tc_SPReg;
  51.     NewList(&newtask->tc_MemEntry);
  52.     AddHead(&newtask->tc_MemEntry,(struct Node *)ml);
  53.     task2=(struct Task *)AddTask(newtask,initpc,0);
  54.     if (SysBase->LibNode.lib_Version>36 && !task2)
  55.     {
  56.       FreeEntry(ml); newtask=NULL;
  57.     }
  58.   }
  59.   else
  60.     newtask=NULL;
  61.  
  62.   return newtask;
  63. }
  64.  
  65.